// components/classSearch/search.js
import utils from '../../utils/util.js'
import { config } from '../../utils/config'
Component({
    /**
     * Component properties
     */
    properties: {
        categoryActive: Number,
        searchObj: Object
    },

    /**
     * Component initial data
     */
    data: {
        imgUrl: config.imgUrl,
        searchTip: false,
        inputValue: ''
    },

    /**
     * Component methods
     */
    methods: {
        /**/
        searchTip() {
            if (this.data.inputValue) {
                this.setData({
                    searchTip: true
                })
            } else {
                this.setData({
                    searchTip: !this.data.searchTip
                })
            }

        },
        /*搜索失去焦点*/
        inputBlur() {
            setTimeout(() => {
                if (this.data.inputValue) {
                    this.setData({
                        searchTip: true
                    })
                } else {
                    this.setData({
                        searchTip: false
                    })
                }
            }, 100);

        },
        /*搜索*/
        searchInput: function(e) {
            let inputValue = e.detail.value;

            if (inputValue) {
                this.setData({
                    inputValue,
                    deleteBtn: true
                })
            } else {
                this.setData({
                    deleteBtn: false,
                })
            }

        },
        /*删除搜索框内容  searchTip true隐藏  false显示*/
        deleteSearch() {
            console.log(1);
            setTimeout(() => {
                this.setData({
                    inputValue: '',
                    deleteBtn: false,
                    searchTip: false
                })
            }, 0);
            this.triggerEvent('searchHandleBtn', { inputValue: '' });
        },
        /*搜索按钮*/
        searchHandle() {
            this.setData({
                searchTip: true
            })
            
            /* categoryActive 1菜品   2菜谱    */
            this.triggerEvent('searchHandleBtn', { inputValue: this.data.inputValue });
        },
    }
})